
# OUTPUT PATHS

# Where the headers will be stored
INCLUDEDIR=$(HOME)/include
# where the executables will be stored
BINDIR=$(HOME)/bin
# where the shared objects will be stored
SODIR=$(HOME)/shared_objects

# INPUT PATHS

# location of samtools (optional)
SAMTOOLS=/home/garyc/software/samtools/samtools-1.0

include utilities_paths.mk

# COMPILERS AND LINKERS
CC = g++
C=gcc
LINKER = g++
# shared object library file name
SO=gwasutil
SO_FILE=$(SO).so

#COMPILER AND LINKER FLAGS

CFLAGS_COMMON=-Wall -I .  -I $(INCLUDEDIR) -fPIC
LFLAGS_COMMON=-lm -lgsl -lgslcblas
CFLAGS_SAMTOOLS=-I$(SAMTOOLS) -I$(SAMTOOLS)/htslib-1.0 
LFLAGS_SAMTOOLS=-lz  
LFLAGS_UNIT=-L$(SODIR) -l$(SO)

PREPROC=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
PREPROC_UNIT=-D_UNIT_TEST

#STANDALONE_OBJS=compress_bam.o transpose_float.o standardize_rows.o marshall_rows.o convertplink2R.o transpose_bin.o

SHARED_OBJS=fast_svd.o random_access.o plink_data.o
EXECUTABLES=standardize_rows compress_bam fast_svd transpose_float  unmarshall_rows marshall_rows random_access_unit convertplink2R transpose_bin plink_data plink_data_unit convertgwa2plink

all: lib$(SO) $(EXECUTABLES) 

clean:
	rm -fr *.o $(SODIR)/* $(EXECUTABLES)

lib$(SO): $(SHARED_OBJS)  *.hpp
	cp *.hpp $(INCLUDEDIR)
	$(LINKER) -shared -o $(SODIR)/lib$(SO_FILE) $(LFLAGS_COMMON) $(SHARED_OBJS)


# OBJECT FILE DIRECTIVES

transpose_float.o: transpose_float.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

convertplink2R.o: convertplink2R.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

standardize_rows.o: standardize_rows.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

marshall_rows.o: marshall_rows.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

unmarshall_rows.o: unmarshall_rows.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

transpose_bin.o: transpose_bin.cpp random_access.hpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

dot_product.o: dot_product.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<

compress_bam.o: compress_bam.cpp
	$(CC) $(CFLAGS_COMMON) $(CFLAGS_SAMTOOLS) $(PREPROC) -c $<

random_access.o: random_access.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<
	$(CC) $(CFLAGS_COMMON) $(PREPROC) $(PREPROC_UNIT) -o random_access_unit.o -c $<

plink_data.o: plink_data.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<
	$(CC) $(CFLAGS_COMMON) $(PREPROC) $(PREPROC_UNIT) -o plink_data_unit.o -c $<

fast_svd.o: fast_svd.cpp
	$(CC) $(CFLAGS_COMMON) $(PREPROC) -c $<
	$(CC) $(CFLAGS_COMMON) $(PREPROC) $(PREPROC_UNIT) -o fast_svd_unit.o -c $<

# EXECUTABLE DIRECTIVES

transpose_float: transpose_float.o
	$(LINKER) -o $(BINDIR)/transpose_float $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

convertplink2R: convertplink2R.o
	$(LINKER) -o $(BINDIR)/convertplink2R $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

standardize_rows: standardize_rows.o
	$(LINKER) -o $(BINDIR)/standardize_rows $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

marshall_rows: marshall_rows.o
	$(LINKER) -o $(BINDIR)/marshall_rows $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

unmarshall_rows: unmarshall_rows.o
	$(LINKER) -o $(BINDIR)/unmarshall_rows $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

transpose_bin: transpose_bin.o
	$(LINKER) -o $(BINDIR)/transpose_bin $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

dot_product: dot_product.o
	$(LINKER) -o $(BINDIR)/dot_product $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

compress_bam: compress_bam.o
	$(LINKER) -o $(BINDIR)/compress_bam  $(LFLAGS_COMMON) $(LFLAGS_SAMTOOLS) $(LFLAGS_UNIT) $< $(SAMTOOLS)/libbam.a $(SAMTOOLS)/htslib-1.0/libhts.a

random_access: random_access_unit.o
	$(LINKER) -o $(BINDIR)/random_access $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

plink_data: plink_data_unit.o
	$(LINKER) -o $(BINDIR)/plink_data $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

fast_svd: fast_svd_unit.o
	$(LINKER) -o $(BINDIR)/fast_svd $(LFLAGS_COMMON) $(LFLAGS_UNIT) $<

